﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using WindowsForms.AOnline.Presenter.Dictionary.Vendor;
using WindowsForms.AOnline.View.Dictionary;
using WindowsForms.AOnline.WindowsForm.FormBase;
using WindowsForms.AOnline.WindowsForm.Resources;

namespace WindowsForms.AOnline.WindowsForm.FormDictionary
{
    public partial class FrmXtraVendorDetail : FrmXtraBaseCategoryDetail, IVendorView
    {
        private readonly VendorPresenter _vendorPresenter;
        public FrmXtraVendorDetail()
        {
            InitializeComponent();
            _vendorPresenter = new VendorPresenter(this);
        }

        public long VendorId { get; set; }



        public string Code
        {
            get { return txtCode.Text; }
            set { txtCode.Text = value; }
        }

        /// <summary>
        /// Gets or sets the full name.
        /// </summary>
        /// <value>
        /// The full name.
        /// </value>
        public string VendorName  
        {
            get { return txtFullName.Text; }
            set { txtFullName.Text = value; }
        }

        public string Address
        {
            get { return txtAddress.Text; }
            set { txtAddress.Text = value; }
        }

        public string ContactName
        {
            get { return txtContactName.Text; }
            set { txtContactName.Text = value; }
        }

        public string PhoneNumber
        {
            get { return txtPhone.Text; }
            set { txtPhone.Text = value; }
        }

        public string Fax
        {
            get { return txtFax.Text; }
            set { txtFax.Text = value; }
        }

        public string Description
        {
            get { return txtWebsite.Text; }
            set { txtWebsite.Text = value; }
        }

        public bool IsActive
        {
            get { return cbIsActive.Checked; }
            set { cbIsActive.Checked = value; }
        }

        public long UnitId { get; set; }

        /// <summary>
        /// Initializes the data.
        /// </summary>
        protected override void InitData()
        {
            if (KeyValue != null)
            {
                _vendorPresenter.Display(KeyValue);
            }

        }

        /// <summary>
        /// Valids the data.
        /// </summary>
        /// <returns></returns>
        protected override bool ValidData()
        {
            if (string.IsNullOrEmpty(Code))
            {
                XtraMessageBox.Show(ResourceHelper.GetResourceValueByName("ResVendorCode"),
                                ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtCode.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(Name))
            {
                XtraMessageBox.Show(ResourceHelper.GetResourceValueByName("ResVendorName"),
                                ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtFullName.Focus();
                return false;
            }
            return true;
        }

        /// <summary>
        /// Saves the data.
        /// </summary>
        /// <returns></returns>
        protected override string SaveData()
        {
            return _vendorPresenter.Save();
        }

        /// <summary>
        /// Focuses the control.
        /// </summary>
        protected override void InitControls()
        {
            txtCode.Focus();
            groupboxMain.Text = ResourceHelper.GetResourceValueByName("ResCommonCaption");
            grbContactInfo.Text = ResourceHelper.GetResourceValueByName("ResContactCaption");
            base.InitControls();
        }

    }
}